<template>
  <div class="jobs-page">
    <GetBioJobNavbar />
    
    <div class="jobs-container">
      <!-- Intro Section -->
      <div class="intro-section">
        <p class="intro-text">
          24/7 real-time updates across thousands of Biopharma, Biotech & Life Science jobs — tailored to maximize your chances of landing the offer.
        </p>
      </div>

      <!-- Tabs -->
      <div class="tabs-section">
        <el-tabs v-model="activeTab" @tab-click="handleTabClick">
          <el-tab-pane label="Job Board" name="job-board"></el-tab-pane>
          <el-tab-pane label="Saved" name="saved"></el-tab-pane>
        </el-tabs>
      </div>

      <!-- Filters Card -->
      <el-card class="filters-card">
        <el-form :model="filters" label-width="120px" class="filters-form">
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :md="8">
              <el-form-item label="Keyword">
                <el-input
                  v-model="filters.keyword"
                  placeholder="Job title, company, or keywords"
                  prefix-icon="el-icon-search"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8">
              <el-form-item label="Location">
                <el-select v-model="filters.location" placeholder="All Locations" style="width: 100%">
                  <el-option label="All Locations" value="all"></el-option>
                  <el-option label="San Francisco, CA" value="sf"></el-option>
                  <el-option label="Boston, MA" value="boston"></el-option>
                  <el-option label="Cambridge, MA" value="cambridge"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8">
              <el-form-item label="Job Type">
                <el-select v-model="filters.jobType" placeholder="All Types" style="width: 100%">
                  <el-option label="All Types" value="all"></el-option>
                  <el-option label="Full-time" value="fulltime"></el-option>
                  <el-option label="Part-time" value="parttime"></el-option>
                  <el-option label="Contract" value="contract"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8">
              <el-form-item label="Experience Level">
                <el-select v-model="filters.experienceLevel" placeholder="All Levels" style="width: 100%">
                  <el-option label="All Levels" value="all"></el-option>
                  <el-option label="Entry Level" value="entry"></el-option>
                  <el-option label="Mid Level" value="mid"></el-option>
                  <el-option label="Senior Level" value="senior"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8">
              <el-form-item label="Company Category">
                <el-select v-model="filters.companyCategory" placeholder="All Categories" style="width: 100%">
                  <el-option label="All Categories" value="all"></el-option>
                  <el-option label="Biotech" value="biotech"></el-option>
                  <el-option label="Pharma" value="pharma"></el-option>
                  <el-option label="Life Science" value="lifescience"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8">
              <el-form-item label="Work Mode">
                <el-select v-model="filters.workMode" placeholder="All Modes" style="width: 100%">
                  <el-option label="All Modes" value="all"></el-option>
                  <el-option label="Remote" value="remote"></el-option>
                  <el-option label="Hybrid" value="hybrid"></el-option>
                  <el-option label="On-site" value="onsite"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8">
              <el-form-item label="Job Function">
                <el-select v-model="filters.jobFunction" placeholder="All Functions" style="width: 100%">
                  <el-option label="All Functions" value="all"></el-option>
                  <el-option label="R&D" value="rd"></el-option>
                  <el-option label="Clinical" value="clinical"></el-option>
                  <el-option label="Regulatory" value="regulatory"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8">
              <el-form-item label="Posting Time">
                <el-select v-model="filters.postingTime" placeholder="Any time" style="width: 100%">
                  <el-option label="Any time" value="all"></el-option>
                  <el-option label="Last 24 hours" value="24h"></el-option>
                  <el-option label="Last 3 days" value="3d"></el-option>
                  <el-option label="Last week" value="1w"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="filter-actions">
            <el-button @click="clearFilters">Clear Filters</el-button>
            <el-button type="primary" @click="searchJobs">Search Jobs</el-button>
          </div>
        </el-form>
      </el-card>

      <!-- Premium Upgrade Notice -->
      <div class="premium-notice">
        <i class="el-icon-lock"></i>
        <span>Upgrade to Premium to access the latest 3 days' job postings. <a href="/pricing">Click to learn more about Premium</a></span>
      </div>

      <!-- Jobs List -->
      <div class="jobs-list-section">
        <div class="jobs-header">
          <span class="jobs-count">{{ filteredJobs.length }} jobs found</span>
          <div class="sort-section">
            <span>Sort by:</span>
            <el-select v-model="sortBy" style="width: 150px; margin-left: 8px;">
              <el-option label="Relevance" value="relevance"></el-option>
              <el-option label="Date Posted" value="date"></el-option>
              <el-option label="Salary" value="salary"></el-option>
            </el-select>
          </div>
        </div>

        <div class="jobs-list">
          <div
            v-for="job in filteredJobs"
            :key="job.id"
            class="job-item"
            :class="{ 'premium': job.premium }"
            @click="goToJobDetail(job.id)"
          >
            <div class="job-item-header">
              <h3 class="job-item-title">{{ job.title }}</h3>
              <i class="el-icon-star-off bookmark-icon" :class="{ 'locked': job.premium }"></i>
            </div>
            <div class="job-item-company">{{ job.company }}</div>
            <div class="job-item-meta">
              <span><i class="el-icon-location"></i> {{ job.location }}</span>
              <span><i class="el-icon-briefcase"></i> {{ job.type }}</span>
              <span><i class="el-icon-house"></i> {{ job.workMode }}</span>
            </div>
            <div class="job-item-tags">
              <span class="job-tag">{{ job.level }}</span>
              <span class="job-tag">{{ job.function }}</span>
              <span class="job-tag" v-if="job.category">{{ job.category }}</span>
            </div>
            <div class="job-item-description">{{ job.description }}</div>
            <div class="job-item-footer">
              <span class="job-item-posted">Posted {{ job.posted }}</span>
              <el-button
                :type="job.premium ? 'info' : 'primary'"
                size="small"
                :disabled="job.premium"
              >
                <i v-if="job.premium" class="el-icon-lock"></i>
                {{ job.premium ? 'Premium Required' : 'Apply Now' }}
              </el-button>
            </div>
          </div>
        </div>

        <!-- Pagination -->
        <el-pagination
          :current-page="currentPage"
          :page-size="pageSize"
          :total="totalJobs"
          layout="prev, pager, next"
          @current-change="handlePageChange"
          class="pagination"
        ></el-pagination>
      </div>
    </div>

    <GetBioJobFooter />
  </div>
</template>

<script>
export default {
  name: 'JobsPage',
  data() {
    return {
      activeTab: 'job-board',
      filters: {
        keyword: '',
        location: 'all',
        jobType: 'all',
        experienceLevel: 'all',
        companyCategory: 'all',
        workMode: 'all',
        jobFunction: 'all',
        postingTime: 'all'
      },
      sortBy: 'relevance',
      currentPage: 1,
      pageSize: 10,
      jobs: [
        {
          id: 1,
          title: 'Senior Research Scientist - Immunology',
          company: 'BioGenesis Therapeutics',
          location: 'San Francisco, CA',
          type: 'Full-time',
          workMode: 'Hybrid',
          level: 'Senior Level',
          function: 'Research',
          category: 'Biotech',
          posted: '2 days ago',
          description: 'Lead immunology research programs focused on autoimmune diseases. Requires PhD in Immunology with 8+ years experience in drug discovery.',
          premium: false
        },
        {
          id: 2,
          title: 'Clinical Data Manager',
          company: 'Vertex Pharmaceuticals',
          location: 'Boston, MA',
          type: 'Full-time',
          workMode: 'Remote',
          level: 'Mid Level',
          function: 'Clinical',
          category: '',
          posted: '5 days ago',
          description: 'Manage clinical trial data integrity and database design. Experience with EDC systems and regulatory submissions required.',
          premium: false
        },
        {
          id: 3,
          title: 'Regulatory Affairs Specialist',
          company: 'Moderna',
          location: 'Cambridge, MA',
          type: 'Full-time',
          workMode: 'On-site',
          level: 'Entry Level',
          function: 'Regulatory',
          category: '',
          posted: '35 days ago',
          description: 'Support regulatory submissions and compliance activities. Bachelor\'s degree in life sciences required.',
          premium: true
        }
      ]
    }
  },
  computed: {
    filteredJobs() {
      return this.jobs.filter(job => {
        if (this.filters.keyword && !job.title.toLowerCase().includes(this.filters.keyword.toLowerCase())) {
          return false
        }
        return true
      })
    },
    totalJobs() {
      return this.filteredJobs.length
    }
  },
  methods: {
    handleTabClick(tab) {
      console.log('Tab clicked:', tab.name)
    },
    clearFilters() {
      this.filters = {
        keyword: '',
        location: 'all',
        jobType: 'all',
        experienceLevel: 'all',
        companyCategory: 'all',
        workMode: 'all',
        jobFunction: 'all',
        postingTime: 'all'
      }
    },
    searchJobs() {
      // Implement search logic
      console.log('Searching jobs with filters:', this.filters)
    },
    goToJobDetail(jobId) {
      this.$router.push(`/jobs/${jobId}`)
    },
    handlePageChange(page) {
      this.currentPage = page
    }
  }
}
</script>

<style scoped>
.jobs-page {
  min-height: 100vh;
  background-color: #1a1a1a;
  color: #fff;
}

.jobs-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.intro-section {
  padding: 24px 0;
  text-align: center;
}

.intro-text {
  color: #fff;
  font-size: 16px;
  max-width: 800px;
  margin: 0 auto;
}

.tabs-section {
  margin-bottom: 24px;
}

.tabs-section /deep/ .el-tabs__header {
  margin: 0;
}

.tabs-section /deep/ .el-tabs__nav-wrap::after {
  background-color: #333;
}

.tabs-section /deep/ .el-tabs__item {
  color: #999;
}

.tabs-section /deep/ .el-tabs__item.is-active {
  color: #fff;
}

.tabs-section /deep/ .el-tabs__active-bar {
  background-color: #fff;
}

.filters-card {
  background-color: #fff;
  margin-bottom: 24px;
}

.filters-card /deep/ .el-card__body {
  padding: 24px;
}

.filters-form {
  margin-top: 0;
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

.premium-notice {
  background-color: #2a2a2a;
  padding: 16px;
  border-radius: 4px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
}

.premium-notice i {
  font-size: 20px;
  color: #ff6b35;
}

.premium-notice a {
  color: #4a9eff;
  text-decoration: none;
}

.jobs-list-section {
  background-color: #1a1a1a;
}

.jobs-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  color: #fff;
}

.jobs-count {
  font-size: 16px;
  font-weight: 500;
}

.sort-section {
  display: flex;
  align-items: center;
}

.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.job-item {
  background-color: #fff;
  border-radius: 8px;
  padding: 24px;
  cursor: pointer;
  transition: transform 0.2s;
}

.job-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.job-item.premium {
  background-color: #2a2a2a;
  color: #fff;
}

.job-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.job-item-title {
  font-size: 20px;
  font-weight: bold;
  color: #000;
  margin: 0;
}

.job-item.premium .job-item-title {
  color: #fff;
}

.bookmark-icon {
  font-size: 20px;
  color: #ccc;
  cursor: pointer;
}

.bookmark-icon.locked {
  opacity: 0.5;
}

.job-item-company {
  font-size: 16px;
  color: #333;
  margin-bottom: 12px;
}

.job-item.premium .job-item-company {
  color: #fff;
}

.job-item-meta {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.job-item-meta span {
  font-size: 14px;
  color: #666;
  display: flex;
  align-items: center;
  gap: 4px;
}

.job-item.premium .job-item-meta span {
  color: #ccc;
}

.job-item-tags {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.job-tag {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  background-color: #f5f5f5;
  color: #666;
}

.job-item.premium .job-tag {
  background-color: #3a3a3a;
  color: #fff;
}

.job-item-description {
  font-size: 14px;
  color: #666;
  line-height: 1.6;
  margin-bottom: 16px;
}

.job-item.premium .job-item-description {
  color: #ccc;
}

.job-item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 16px;
  border-top: 1px solid #e5e5e5;
}

.job-item.premium .job-item-footer {
  border-top-color: #444;
}

.job-item-posted {
  font-size: 12px;
  color: #999;
}

.job-item.premium .job-item-posted {
  color: #999;
}

.pagination {
  margin-top: 32px;
  display: flex;
  justify-content: center;
}

.pagination /deep/ .el-pagination {
  color: #fff;
}

.pagination /deep/ .el-pagination .el-pager li {
  background-color: #2a2a2a;
  color: #fff;
}

.pagination /deep/ .el-pagination .el-pager li.active {
  background-color: #fff;
  color: #000;
}

@media screen and (max-width: 768px) {
  .jobs-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  
  .filter-actions {
    flex-direction: column;
  }
  
  .filter-actions .el-button {
    width: 100%;
  }
}
</style>

